﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FaceSharp.Api.RestApi;

namespace FaceSharp.Api.Objects
{
    public class Page : RestBase
    {
        public Page(IFacebookCore facebookCore) : base(facebookCore)
        {
        }
        public bool IsAdmin(long pageId,long userId)
        {
            var xmlResult = base.MakeRestRequest(
                "pages.isAdmin",
                new Dictionary<string, string>()
                    {
                        {"page_id", pageId.ToString()},
                        {"uid", userId.ToString()}
                    },responseFormat:ResponseFormat.Xml
                );
            XNamespace ns = "http://api.facebook.com/1.0/";
            var xdoc = XDocument.Parse(xmlResult);
            var adminStatus = (from response in xdoc.Descendants(ns + "pages_isAdmin_response")
                            select response.Value == "1").FirstOrDefault();
            return adminStatus;
        }
    }
}
